package com.aebiz.usercenter.outer.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aebiz.usercenter.common.util.ConstatFinalUtil;
import com.aebiz.usercenter.outer.service.IOuterService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

@Controller
@RequestMapping("/outer/json")
public class JsonOuterController {
	
	@Resource
	private IOuterService outerService;
	

	@RequestMapping(value="verfiyToken",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String verfiyToken(String json)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--verfiyToken--");
		JSONObject resultJSON = new JSONObject() ; 
		/*处理参数*/
		if(json==null)
		{
			json="";
		}
		System.out.println(json+"==============JSON===============");
		if(!"".equalsIgnoreCase(json))
		{
			JSONObject reqJSON=new JSONObject();
			try {
				reqJSON=(JSONObject) JSON.parse(json);
				try {
					/*取到版本*/
					String version = reqJSON.getString("version");
					if("1".equalsIgnoreCase(version))
					{
						resultJSON=this.outerService.verfiyToken01Service(reqJSON);
					}else
					{
						/* 版本号不正确 */
						resultJSON.put("code", "11");
						resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("11") + "");
					}
				} catch (Exception e) {
					resultJSON.put("code", "13");
					resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("13") + ";" + e.toString());
				}
			} catch (Exception e) {
				/* 上传的json数据格式不正确 */
				resultJSON.put("code", "10");
				resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("10") + ";" + e.toString());
			}
		}else
		{
			/* 请上传上行参数 */
			resultJSON.put("code", "9");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("9") + "");
		}
		return resultJSON.toJSONString();
	}
}
